﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Display
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;
using System.Runtime.CompilerServices;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Provides access to a display / screen for rendering operations.</para>
  /// </summary>
  [NativeHeader("Runtime/Graphics/DisplayManager.h")]
  [UsedByNativeCode]
  public class Display
  {
    internal IntPtr nativeDisplay;
    /// <summary>
    ///   <para>The list of connected displays.</para>
    /// </summary>
    public static Display[] displays = new Display[1]
    {
      new Display()
    };
    private static Display _mainDisplay = Display.displays[0];
    private static int m_ActiveEditorGameViewTarget = 0;

    internal Display() => this.nativeDisplay = new IntPtr(0);

    internal Display(IntPtr nativeDisplay) => this.nativeDisplay = nativeDisplay;

    /// <summary>
    ///   <para>Horizontal resolution that the display is rendering at.</para>
    /// </summary>
    public int renderingWidth
    {
      get
      {
        int w = 0;
        int h = 0;
        Display.GetRenderingExtImpl(this.nativeDisplay, out w, out h);
        return w;
      }
    }

    /// <summary>
    ///   <para>Vertical resolution that the display is rendering at.</para>
    /// </summary>
    public int renderingHeight
    {
      get
      {
        int w = 0;
        int h = 0;
        Display.GetRenderingExtImpl(this.nativeDisplay, out w, out h);
        return h;
      }
    }

    /// <summary>
    ///   <para>Horizontal native display resolution.</para>
    /// </summary>
    public int systemWidth
    {
      get
      {
        int w = 0;
        int h = 0;
        Display.GetSystemExtImpl(this.nativeDisplay, out w, out h);
        return w;
      }
    }

    /// <summary>
    ///   <para>Vertical native display resolution.</para>
    /// </summary>
    public int systemHeight
    {
      get
      {
        int w = 0;
        int h = 0;
        Display.GetSystemExtImpl(this.nativeDisplay, out w, out h);
        return h;
      }
    }

    /// <summary>
    ///   <para>Color RenderBuffer.</para>
    /// </summary>
    public RenderBuffer colorBuffer
    {
      get
      {
        RenderBuffer color;
        Display.GetRenderingBuffersImpl(this.nativeDisplay, out color, out RenderBuffer _);
        return color;
      }
    }

    /// <summary>
    ///   <para>Depth RenderBuffer.</para>
    /// </summary>
    public RenderBuffer depthBuffer
    {
      get
      {
        RenderBuffer depth;
        Display.GetRenderingBuffersImpl(this.nativeDisplay, out RenderBuffer _, out depth);
        return depth;
      }
    }

    /// <summary>
    ///   <para>Gets the state of the display and returns true if the display is active and false if otherwise.</para>
    /// </summary>
    public bool active => Display.GetActiveImpl(this.nativeDisplay);

    /// <summary>
    ///   <para>True when the back buffer requires an intermediate texture to render.</para>
    /// </summary>
    public bool requiresBlitToBackbuffer
    {
      get
      {
        int int32 = this.nativeDisplay.ToInt32();
        return int32 < HDROutputSettings.displays.Length && HDROutputSettings.displays[int32].available && HDROutputSettings.displays[int32].active || Display.RequiresBlitToBackbufferImpl(this.nativeDisplay);
      }
    }

    /// <summary>
    ///   <para>True when doing a blit to the back buffer requires manual color space conversion.</para>
    /// </summary>
    public bool requiresSrgbBlitToBackbuffer
    {
      get => Display.RequiresSrgbBlitToBackbufferImpl(this.nativeDisplay);
    }

    /// <summary>
    ///   <para>Activates an external display. For example, a secondary monitor connected to the system.</para>
    /// </summary>
    public void Activate() => Display.ActivateDisplayImpl(this.nativeDisplay, 0, 0, 60);

    public void Activate(int width, int height, int refreshRate)
    {
      Display.ActivateDisplayImpl(this.nativeDisplay, width, height, refreshRate);
    }

    /// <summary>
    ///   <para>Windows platforms only. Sets rendering size and position on screen.</para>
    /// </summary>
    /// <param name="width">Windows platforms only. The width of the window.</param>
    /// <param name="height">Windows platforms only. The height of the window.</param>
    /// <param name="x">Windows platforms only. The x position of the window.</param>
    /// <param name="y">Windows platforms only. The y position of the window.</param>
    public void SetParams(int width, int height, int x, int y)
    {
      Display.SetParamsImpl(this.nativeDisplay, width, height, x, y);
    }

    /// <summary>
    ///   <para>Sets rendering resolution for the display.</para>
    /// </summary>
    /// <param name="w">The rendering width in pixels.</param>
    /// <param name="h">The rendering height in pixels.</param>
    public void SetRenderingResolution(int w, int h)
    {
      Display.SetRenderingResolutionImpl(this.nativeDisplay, w, h);
    }

    [Obsolete("MultiDisplayLicense has been deprecated.", false)]
    public static bool MultiDisplayLicense() => true;

    /// <summary>
    ///   <para>Query relative mouse coordinates.</para>
    /// </summary>
    /// <param name="inputMouseCoordinates">Mouse Input Position as Coordinates.</param>
    public static Vector3 RelativeMouseAt(Vector3 inputMouseCoordinates)
    {
      int rx = 0;
      int ry = 0;
      int x = (int) inputMouseCoordinates.x;
      int y = (int) inputMouseCoordinates.y;
      Vector3 vector3;
      vector3.z = (float) Display.RelativeMouseAtImpl(x, y, out rx, out ry);
      vector3.x = (float) rx;
      vector3.y = (float) ry;
      return vector3;
    }

    /// <summary>
    ///   <para>Main Display.</para>
    /// </summary>
    public static Display main => Display._mainDisplay;

    /// <summary>
    ///   <para>Get the Editors active GameView display target.</para>
    /// </summary>
    public static int activeEditorGameViewTarget
    {
      get => Display.m_ActiveEditorGameViewTarget;
      internal set => Display.m_ActiveEditorGameViewTarget = value;
    }

    [RequiredByNativeCode]
    private static void RecreateDisplayList(IntPtr[] nativeDisplay)
    {
      if (nativeDisplay.Length == 0)
        return;
      Display.displays = new Display[nativeDisplay.Length];
      for (int index = 0; index < nativeDisplay.Length; ++index)
        Display.displays[index] = new Display(nativeDisplay[index]);
      Display._mainDisplay = Display.displays[0];
    }

    [RequiredByNativeCode]
    private static void FireDisplaysUpdated()
    {
      if (Display.onDisplaysUpdated == null)
        return;
      Display.onDisplaysUpdated();
    }

    public static event Display.DisplaysUpdatedDelegate onDisplaysUpdated = null;

    [FreeFunction("UnityDisplayManager_DisplaySystemResolution")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetSystemExtImpl(IntPtr nativeDisplay, out int w, out int h);

    [FreeFunction("UnityDisplayManager_DisplayRenderingResolution")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetRenderingExtImpl(IntPtr nativeDisplay, out int w, out int h);

    [FreeFunction("UnityDisplayManager_GetRenderingBuffersWrapper")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void GetRenderingBuffersImpl(
      IntPtr nativeDisplay,
      out RenderBuffer color,
      out RenderBuffer depth);

    [FreeFunction("UnityDisplayManager_SetRenderingResolution")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetRenderingResolutionImpl(IntPtr nativeDisplay, int w, int h);

    [FreeFunction("UnityDisplayManager_ActivateDisplay")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void ActivateDisplayImpl(
      IntPtr nativeDisplay,
      int width,
      int height,
      int refreshRate);

    [FreeFunction("UnityDisplayManager_SetDisplayParam")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern void SetParamsImpl(
      IntPtr nativeDisplay,
      int width,
      int height,
      int x,
      int y);

    [FreeFunction("UnityDisplayManager_RelativeMouseAt")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern int RelativeMouseAtImpl(int x, int y, out int rx, out int ry);

    [FreeFunction("UnityDisplayManager_DisplayActive")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool GetActiveImpl(IntPtr nativeDisplay);

    [FreeFunction("UnityDisplayManager_RequiresBlitToBackbuffer")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool RequiresBlitToBackbufferImpl(IntPtr nativeDisplay);

    [FreeFunction("UnityDisplayManager_RequiresSRGBBlitToBackbuffer")]
    [MethodImpl(MethodImplOptions.InternalCall)]
    private static extern bool RequiresSrgbBlitToBackbufferImpl(IntPtr nativeDisplay);

    public delegate void DisplaysUpdatedDelegate();
  }
}
